#!/usr/bin/python3
# coding:utf-8

import rospy
import os
import numpy as np
from std_msgs.msg import Int32
import time
import shutil
class Host_C:
    def __init__(self):
        rospy.init_node('Host_C', anonymous=True)
        self.rate = rospy.Rate(10)
        self.u_path = rospy.get_param("/host_c/u_path")
        self.tgt_path = rospy.get_param("/host_c/tgt_path")
        
        self.global_status = 0

        rospy.Subscriber("/global_status", Int32, self.cb_global_status)
        self.status_publish = rospy.Publisher("/host_c_status", Int32, queue_size=1)

    def cb_global_status(self,data):
        self.global_status = data.data
        if self.global_status == 3:
            while not os.path.exists(self.u_path):
                pass
            file_list = os.listdir(self.u_path)
            for file in file_list:
                if os.path.exists(os.path.join(self.tgt_path,file)):
                    pass
                shutil.move(os.path.join(self.u_path,file), self.tgt_path)
            self.status_publish.publish(1)
            self.global_status = 0

    def MainLoop(self):
        while not rospy.is_shutdown():
            self.rate.sleep()


if __name__ == '__main__':
    node1 = Host_C()
    node1.MainLoop()

